package com.cn.yunhe.rentcars.web;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.security.auth.Subject;
import javax.servlet.http.HttpServletRequest;

import org.apache.shiro.SecurityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.cn.yunhe.rentcars.mapper.PermissionMapper;
import com.cn.yunhe.rentcars.mapper.ResourceMapper;
import com.cn.yunhe.rentcars.model.Resource;


/**
 * 主页面 动态菜单显示
 * @author 赵志学
 * 2016-8-1
 *
 */
@Controller
public class IndexController {
	
    private static Logger logger = LoggerFactory.getLogger(IndexController.class);
    @Autowired
    private ResourceMapper resourceMapper;
    @Autowired
    private PermissionMapper permissionMapper;
	@RequestMapping("/home")
	public ModelAndView index(Map<String, Object> model,HttpServletRequest request) {
		Map<String,String> map = new HashMap<String,String>();		
		String name = (String) request.getSession().getAttribute("username");		
		//List<Resource> resList = resourceMapper.findResources(map);
		List<Resource> resList = permissionMapper.getPermissionByUser(name);//获得用户的权限信息
		Map<String,Object> rsMap = new HashMap<String,Object>();		
		rsMap.put("resList", resList);		
		return new ModelAndView("home",rsMap);
	}
	
	@RequestMapping("/403")
	public String unauthorizedRole(){
		logger.info("------没有权限访问-------");
		return "403";
	}
}
